package com.store.app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.store.app.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liuwy on 2016/2/19.
 */
public class Stores_ServiceAdapter extends RecyclerView.Adapter<Stores_ServiceAdapter.ViewHolder> {


    private List<Integer> serviceList;

    private Context context;

    private LayoutInflater mInflater;

    public Stores_ServiceAdapter(String activity_servcie, Context context) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        serviceList = new ArrayList<>();

        if(TextUtils.isEmpty(activity_servcie)){
            activity_servcie = "[]";
        }
        String temp_activity_servcie = activity_servcie.substring(1, activity_servcie.length() - 1).replaceAll(" ", "");
        Log.v("zyl","传递进适配器temp_activity_servcie："+temp_activity_servcie);
        if (!TextUtils.isEmpty(temp_activity_servcie)) {
            String[] sourceStrArray = temp_activity_servcie.split(",");
            for (int i = 0; i < sourceStrArray.length; i++) {
                if(!serviceList.contains(Integer.valueOf(sourceStrArray[i]).intValue())){
                    serviceList.add(Integer.valueOf(sourceStrArray[i]).intValue());//Integer.parseInt(sourceStrArray[i]));
                }
            }
        }

    }

    public void setlist(List<Integer> serviceList) {
        this.serviceList = serviceList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_stores_service,
                parent, false);
        ViewHolder viewHolder = null;
        viewHolder = new ViewHolder(view);

        viewHolder.ivService = (ImageView) view.findViewById(R.id.stores_service_img);
        viewHolder.tvName = (TextView) view.findViewById(R.id.stores_service_tv);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                MobclickAgent.onEvent(context, "004");
//                Intent intent = new Intent();
//                intent.setClass(context, ServiceActivity.class);
//
//                context.startActivity(intent);
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        int no = serviceList.get(position);
        switch (no) {
            case 1:
                holder.ivService.setBackgroundResource(R.drawable.wifi_bigiconorg);
                holder.tvName.setText("免费WiFi");
                break;
            case 2:
                holder.ivService.setBackgroundResource(R.drawable.wc_bigiconorg);
                holder.tvName.setText("免费厕所");
                break;
            case 3:
                holder.ivService.setBackgroundResource(R.drawable.hot2_bigiconorg);
                holder.tvName.setText("免费热水");
                break;
            case 4:
                holder.ivService.setBackgroundResource(R.drawable.hot_bigiconorg);
                holder.tvName.setText("食物加热");
                break;
            case 5:
                holder.ivService.setBackgroundResource(R.drawable.bigicon_org);
                holder.tvName.setText("免费打气");
                break;
            case 6:
                holder.ivService.setBackgroundResource(R.drawable.dian_bigiconorg);
                holder.tvName.setText("手机充电");
                break;
            case 7:
                holder.ivService.setBackgroundResource(R.drawable.bre_bigiconorg);
                holder.tvName.setText("早餐");
                break;
            case 8:
                holder.ivService.setBackgroundResource(R.drawable.ex_bigiconorg);
                holder.tvName.setText("快递收发");
                break;
            case 9:
                holder.ivService.setBackgroundResource(R.drawable.pay_bigiconorg);
                holder.tvName.setText("缴话费");
                break;
            case 10:
                holder.ivService.setBackgroundResource(R.drawable.mill_bigiconorg);
                holder.tvName.setText("鲜奶预订");
                break;
            case 11:
                holder.ivService.setBackgroundResource(R.drawable.fr_bigiconorg);
                holder.tvName.setText("鲜花预订");
                break;
            case 12:
                holder.ivService.setBackgroundResource(R.drawable.ck_bigiconorg);
                holder.tvName.setText("蛋糕预订");
                break;
            case 13:
                holder.ivService.setBackgroundResource(R.drawable.gy_bigiconorg);
                holder.tvName.setText("公益回收箱");
                break;
            case 14:
                holder.ivService.setBackgroundResource(R.drawable.suo_bigiconorg);
                holder.tvName.setText("便民开锁");
                break;
            case 15:
                holder.ivService.setBackgroundResource(R.drawable.sh_group);
                holder.tvName.setText("便民搬家");
                break;
            case 16:
                holder.ivService.setBackgroundResource(R.drawable.tong_bigiconorg);
                holder.tvName.setText("管道疏通");
                break;
            case 17:
                holder.ivService.setBackgroundResource(R.drawable.gx_bigiconorg);
                holder.tvName.setText("干洗代收");
                break;
            case 18:
                holder.ivService.setBackgroundResource(R.drawable.group_copyorg);
                holder.tvName.setText("家政服务");
                break;
            case 19:
                holder.ivService.setBackgroundResource(R.drawable.pay2_bigiconorg);
                holder.tvName.setText("移动支付");
                break;
            case 20:
                holder.ivService.setBackgroundResource(R.drawable.wx_bigiconorg);
                holder.tvName.setText("家电维修");
                break;
            case 21:
                holder.ivService.setBackgroundResource(R.drawable.tool_bigiconorg);
                holder.tvName.setText("工具箱");
                break;
            case 22:
                holder.ivService.setBackgroundResource(R.drawable.yyc_bigiconorg);
                holder.tvName.setText("摇摆车");
                break;
            case 23:
                holder.ivService.setBackgroundResource(R.drawable.tx_bigiconorg);
                holder.tvName.setText("租车代驾");
                break;
            case 24:
                holder.ivService.setBackgroundResource(R.drawable.rc_bigiconorg);
                holder.tvName.setText("手机回收");
                break;
            case 25:
                holder.ivService.setBackgroundResource(R.drawable.ly_bigiconorg);
                holder.tvName.setText("宽带安装");
                break;

        }

    }


    @Override
    public int getItemCount() {
        return serviceList == null ? 0 : serviceList.size();
    }

//    @Override
//    public Object getItem(int position) {
//        return serviceList.get(position);
//    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View arg0) {
            super(arg0);
        }

        ImageView ivService;
        TextView tvName;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

//    @Override
//    public int getItemCount() {
//        return 0;
//    }

//    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//
//        ViewHolder viewHolder ;
//        if (convertView == null) {
//            viewHolder = new ViewHolder();
//
//
//            convertView = LayoutInflater.from(context).inflate(R.layout.services_gallery_item, null);
//
//            viewHolder.ivService = (ImageView) convertView.findViewById(R.id.iv_services);
//            viewHolder.tvName = (TextView) convertView.findViewById(R.id.tv_services);
//            convertView.setTag(viewHolder);
//        } else {
//            viewHolder = (ViewHolder) convertView.getTag();
//        }
//
//
//        ServiceBean serviceBean = serviceList.get(position);
//        viewHolder.ivService.setBackgroundResource(serviceBean.getResId());
//        viewHolder.tvName.setText(serviceBean.getName());
//
//        return convertView;
//    }


//    class ViewHolder {
//        ImageView ivService;
//        TextView tvName;
//    }


}
